package com.plant.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import com.plant.dao.BaseDao;
import com.plant.entity.PgcArticle;
import com.plant.service.ArticleService;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author 植物先生-李琦
 * 
 * 			---下面是注册接口
 */
@Service  //依赖注册 必须写注册 下面在写resource资源
@Transactional
public class ArticleServiceImpl implements ArticleService{
    @Resource(name = "baseDaoImpl")//注解扫描basedao接口方法
    private BaseDao baseDao;

	public boolean addarticle(PgcArticle pa) {	//新建添加文章
		boolean isadd=true; 
		isadd=baseDao.add(pa);
		return isadd;
	}
	public boolean uparticle(PgcArticle pa) {	//修改文章
		boolean isadd=true; 
		baseDao.update(pa);
		return isadd;
	}
	public boolean delarticle(PgcArticle pa) {	//删除文章
		boolean isadd=true; 
		isadd=baseDao.del(pa);
		return isadd;
	}
	
	@SuppressWarnings("unchecked")
	public List<Object> listarticle(PgcArticle pa,Integer page,String time) {//显示文章列表
		List<Object> list3=new ArrayList<Object>();
        System.out.println("你好我是时间"+time);
    	String hql="select a.id,a.title,a.image,a.add_time,b.nickname,b.photo from pgc_article as a,ugc_user as b where a.user_id=("+pa.getUserId()+") and a.user_id=b.id and add_time<? order by add_time desc";//--通过 时间分页查询 显示10条
    	list3=baseDao.findfenye((page-1)*20, 20, hql, time,null);
        return list3;
	}
	
	
	@SuppressWarnings("unchecked")
	public List<Object> onearticle(PgcArticle pa) {		//--显示单篇---修改文章详情
		String hql="select a.id,a.user_id,a.title,a.content,a.image from pgc_article as a where a.id=("+pa.getId()+")";
		return baseDao.lianhe(hql, null);
	}
	
	
	
	public Long articlecount(PgcArticle pa) {//---统计马甲用户创建文章条数
		String hql="select count(id) from PgcArticle where userId=("+pa.getUserId()+")";
		Long lo=baseDao.CountHql(hql);
		System.out.println(lo+"统计马甲用户创建文章条数");
		return lo;
	}
	
	
	public Object oneinf(PgcArticle pa) {   //----返回单个对象
		return baseDao.find(PgcArticle.class, pa.getId());
	}
	
	
	
 }
